// 惰性链
function LazyChain(obj) {
  let isLC = (obj instanceof LazyChain);
  this._calls = isLC ? [...obj._calls] : [];
  this._target = isLC ? obj._target : obj;
}
LazyChain.prototype.invoke = function(methodName, ...args) {
  this._calls.push(function(target) {
    let meth = target[methodName];
    return meth.apply(target, args);
  });
  return this;
}
LazyChain.prototype.exec = function() {
  return this._calls.reduce((target, thunk) => {
    return thunk(target);
  }, this._target);
}
  
let ret = new LazyChain([2, 1, 3]).invoke('sort').exec()
console.log(ret)
  
ret = new LazyChain([2, 1, 3]).invoke('concat', [8, 7, 5, 6]).invoke('sort').invoke('join', ' ').exec()
console.log(ret)

console.log([2,1,3].concat([5,4,6]).sort().join(' '));

  
  
  
  